//
//  UIImageViewExtension.swift
//  Lottery
//
//  Created by 薛永伟 on 2019/1/21.
//  Copyright © 2019年 薛永伟. All rights reserved.
//

import UIKit

extension UIImage {
    
    /// 占位图
    static var placeHolder:UIImage {
        return UIImage.init(named: "placeholder")!
    }
    
    /// 导航返回箭头图
    static var naviBack:UIImage {
        return UIImage(named: "back_icon_white")!.byResize(to: CGSize.init(width: 21, height: 21))
    }
    
    //图片压缩
    func compressImageOnlength(maxLength: Int) -> Data? {
        let maxL = maxLength * 1024
        var compress:CGFloat = 0.9
        let maxCompress:CGFloat = 0.1
        
        var imageData = self.jpegData(compressionQuality: 1)
        while (imageData?.count)! > maxL && compress > maxCompress {
            compress -= 0.1
            imageData = self.jpegData(compressionQuality: compress)
        }
        return imageData
    }
}


